package com.ruoyi.wgjlcData.service.impl;

import com.alibaba.fastjson2.JSON;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.wgjlcData.domain.plat.DataWgjlcWeiqi;
import com.ruoyi.wgjlcData.domain.vo.TestWeiQi;
import com.ruoyi.wgjlcData.mapper.DataWgjlcWeiqiMapper;
import com.ruoyi.wgjlcData.service.IDataWgjlcWeiqiService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.concurrent.Future;


/**
 * 无轨胶轮车尾气测试项Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-02-27
 */
@Service
public class DataWgjlcWeiqiServiceImpl implements IDataWgjlcWeiqiService
{
    @Autowired
    private DataWgjlcWeiqiMapper dataWgjlcWeiqiMapper;

    /**
     * 查询无轨胶轮车尾气测试项
     * 
     * @param weiqiId 无轨胶轮车尾气测试项主键
     * @return 无轨胶轮车尾气测试项
     */
    @Override
    public DataWgjlcWeiqi selectDataWgjlcWeiqiByWeiqiId(Long weiqiId)
    {
        return dataWgjlcWeiqiMapper.selectDataWgjlcWeiqiByWeiqiId(weiqiId);
    }

    /**
     * 查询无轨胶轮车尾气测试项列表
     * 
     * @param dataWgjlcWeiqi 无轨胶轮车尾气测试项
     * @return 无轨胶轮车尾气测试项
     */
    @Override
    public List<DataWgjlcWeiqi> selectDataWgjlcWeiqiList(DataWgjlcWeiqi dataWgjlcWeiqi)
    {
        return dataWgjlcWeiqiMapper.selectDataWgjlcWeiqiList(dataWgjlcWeiqi);
    }

    /**
     * 新增无轨胶轮车尾气测试项
     * 
     * @param dataWgjlcWeiqi 无轨胶轮车尾气测试项
     * @return 结果
     */
    @Override
    public int insertDataWgjlcWeiqi(DataWgjlcWeiqi dataWgjlcWeiqi)
    {
        dataWgjlcWeiqi.setCreateTime(DateUtils.getNowDate());
        return dataWgjlcWeiqiMapper.insertDataWgjlcWeiqi(dataWgjlcWeiqi);
    }

    /**
     * 查询无轨胶轮车-尾气测试项
     *
     * @param dataTaskId
     * @return 无轨胶轮车-尾气测试项
     */
    @Async("threadPoolKy")
    @Override
    public Future<List<DataWgjlcWeiqi>> selectDataWgjlcWeiqiByDataTaskId(Long dataTaskId) {
        List<DataWgjlcWeiqi> dataWgjlcWeiqiEntities = dataWgjlcWeiqiMapper.selectDataWgjlcWeiqiByDataTaskId(dataTaskId);
        if (dataWgjlcWeiqiEntities.size() != 0) {
            dataWgjlcWeiqiEntities.forEach(item -> {
                if (item.getDataList() != null && item.getDataList().length() != 0) {
                    item.setTestWeiQiList(JSON.parseArray(item.getDataList(), TestWeiQi.class));
                    item.setListSize(item.getTestWeiQiList().size());
                }
            });
        }
        return new AsyncResult<>(dataWgjlcWeiqiEntities);
    }

    /**
     * 修改状态为2
     *
     * @param dataTaskId
     */
    @Override
    public int updateDataWgjlcWeiqiByDataTaskId(Long dataTaskId) {
        return dataWgjlcWeiqiMapper.updateDataWgjlcWeiqiByDataTaskId(dataTaskId);
    }

    /**
     * 批量新增无轨胶轮车-尾气测试项
     *
     * @param dataWgjlcWeiqi 无轨胶轮车-尾气测试项
     * @return 结果
     */
    @Override
    public int batchDataWgjlcWeiqi(List<DataWgjlcWeiqi> dataWgjlcWeiqi) {
        return dataWgjlcWeiqiMapper.batchDataWgjlcWeiqi(dataWgjlcWeiqi);
    }

    /**
     * 修改无轨胶轮车尾气测试项
     * 
     * @param dataWgjlcWeiqi 无轨胶轮车尾气测试项
     * @return 结果
     */
    @Override
    public int updateDataWgjlcWeiqi(DataWgjlcWeiqi dataWgjlcWeiqi)
    {
        dataWgjlcWeiqi.setUpdateTime(DateUtils.getNowDate());
        //list转Json字符串
        if(!dataWgjlcWeiqi.getTestWeiQiList().isEmpty()) {
            dataWgjlcWeiqi.setDataList(JSON.toJSONString(dataWgjlcWeiqi.getTestWeiQiList()));
        }
        return dataWgjlcWeiqiMapper.updateDataWgjlcWeiqi(dataWgjlcWeiqi);
    }

    /**
     * 批量删除无轨胶轮车尾气测试项
     * 
     * @param weiqiIds 需要删除的无轨胶轮车尾气测试项主键
     * @return 结果
     */
    @Override
    public int deleteDataWgjlcWeiqiByWeiqiIds(Long[] weiqiIds)
    {
        return dataWgjlcWeiqiMapper.deleteDataWgjlcWeiqiByWeiqiIds(weiqiIds);
    }

    /**
     * 删除无轨胶轮车尾气测试项信息
     * 
     * @param weiqiId 无轨胶轮车尾气测试项主键
     * @return 结果
     */
    @Override
    public int deleteDataWgjlcWeiqiByWeiqiId(Long weiqiId)
    {
        return dataWgjlcWeiqiMapper.deleteDataWgjlcWeiqiByWeiqiId(weiqiId);
    }
}
